Ext.namespace("Plan.ToAudit");

Plan.ToAudit.panel = function(){
	Plan.Audit.win.instance = new Plan.Audit.win();
//	Plan.Audit.win.instance.initData();
	this.store = new Ext.data.Store({
		proxy: new Ext.data.HttpProxy({
			url: '../plan/searchPlanInfo.form?timesnap=' + Date.parse(new Date()),
			method: 'POST'
		}),
		reader: new Ext.data.JsonReader({
			root: 'result',
			totalProperty: 'total',
			id: 'PLAN_ID',
			baseParams : { plan_status:'0',flag:'check'},
			fields: ['PLAN_ID', 'PLAN_TITLE', 'CREATE_USER','CREATE_DATE', 'PLAN_TYPE_NAME', 'AUDIT_ID','PLAN_START_DATE',
			'PLAN_END_DATE','PLAN_STATUS','PLAN_FINISH_STATUS','CREATE_DEP','AUDIT_NAME','CREATE_NAME','DEPARTMENT','PLAN_TYPE_ID','PLAN_LEVEL']
		})
	});
	this.renderStatus = function(value){
		return OMS.PLANSTATUS[value];
	};
	this.sm = new Ext.grid.CheckboxSelectionModel({singleSelect:true});
	this.cm = new Ext.grid.ColumnModel({
	    defaults: {
	        width: 100,
	        sortable: true,
	        align: 'center'
	    },
	    columns: [
	   		this.sm,
			{id: 'PLAN_ID', header: 'ID', width: 50, hidden: true, dataIndex: 'PLAN_ID'},
			{header: '计划名称', width: 200, dataIndex: 'PLAN_TITLE'},
			{header: '计划类型', width: 100, dataIndex: 'PLAN_TYPE_NAME'},
			{header: '制定人', width: 100, dataIndex: 'CREATE_NAME'},
			{header: '审核人', dataIndex: 'AUDIT_NAME'},
			{header: '开始时间', dataIndex: 'PLAN_START_DATE'},
			{header: '结束时间', dataIndex: 'PLAN_END_DATE'},
		//	{header: '剩余天数', dataIndex: 'PLAN_END_DATE',renderer:this.renderDays},
			{header: '制定部门', dataIndex: 'DEPARTMENT'},
			{header: '计划状态', dataIndex: 'PLAN_STATUS',renderer:this.renderStatus}
	    ]
	});
	this.btnAudit = new Ext.Button({
		text:'审核',
		scope:this,
		handler:this.audit
	});
	this.gridPanel = new Ext.grid.GridPanel({
		region:'center',
		store:this.store,
		stripeRows: true, 
		cm:this.cm,
		tbar:[this.btnAudit],
        loadMask: {msg: '加载中，请稍候...'},
        bbar:new Ext.PagingToolbar({
			 pageSize: 15,
	         store: this.store,
	         displayInfo: true,
	         displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
	         emptyMsg: "没有记录..."
		}),
        viewConfig: { forceFit: true },listeners:{
			 beforeload :{    
	    	  	fn : function(thiz,options){
       	          Ext.apply(thiz.baseParams,
       	          { 
       	          	flag:'check',
       	          	 plan_status:0
       	          });    
              },
              scope:this 
	    	}
		}
	});

	Plan.ToAudit.panel.superclass.constructor.call(this,{
		layout:'border',
		renderTo:document.body,
		items:[this.gridPanel],
		listeners:{
			render:this.queryPlan
		}
	});
}
Ext.extend(Plan.ToAudit.panel,Ext.Viewport,{
	audit:function(){
		var sm =this.gridPanel.getSelectionModel();
		var record = sm.getSelections();
		if(record.length==0){
			Utils.warn('请选择一条计划！');
			return ;
		}
		else if(record.length>1){
			Utils.warn('只能选择一条计划！',"警告");
			return;
		}
		var plan = record[0].data;
		Plan.Audit.win.instance.show();
		Plan.Audit.win.instance.initAudit(plan);
	},queryPlan:function(){
		this.store.load({
			params:{
				start : 0,
				limit : 15,
				plan_status:0,
				flag:'check'
				}
		})
	}
});
Ext.onReady(function(){
	Ext.QuickTips.init();
    Ext.BLANK_IMAGE_URL = '../resources/images/default/s.gif';
	Plan.ToAudit.panel.instance = new Plan.ToAudit.panel();
})
